local function get_common_inst()
    local inst = require("prefabs/npc_characters/__00__human_npc_common")():Common_Npc_Create()
    return inst
end

local function wanda()
    local inst = get_common_inst()

    inst.AnimState:SetBuild("wanda")
    inst.soundsname = "wanda"
    inst.prefab_base = "wanda"
    inst.customidleanim = "idle_wanda"  -- 站立休闲动作

    inst.talk_sound = "wanda2/characters/wanda/talk_LP"  --- 旺达音效
    inst:Hide()
    if not TheWorld.ismastersim then
        return inst
    end

    --------------- 把角色皮肤搞成旺达
    inst:DoTaskInTime(0,function()
        pcall(function()
            local skins = {
                ["feet"] = "",
                ["legs"] = "",
                ["hand"] = "",
                ["base"] = "wanda_none",
                ["body"] = ""
            }
            local userid = inst:GetPlayer().userid   ----- 如果该ID玩家没购买那个角色，则会出现威尔逊外观替代
            inst.AnimState:AssignItemSkins(userid, skins.base or "", skins.body or "", skins.hand or "", skins.legs or "", skins.feet or "")
            inst.npc_base_lib:___Set_Skin(inst.AnimState,"wanda","wanda",skins,nil,"normal_skin","wanda")
        end)
        
        
        inst.customidleanim = "idle_wanda"  -- 站立休闲动作
        inst:Show()
    end)
    inst:DoPeriodicTask(0.7, function()
        local pt = inst.npc_base_lib:GetSpawnPoint(inst,math.random(15)/10)
        if pt == nil then
            pt = Vector3(inst.Transform:GetWorldPosition())
        end

        local fx = SpawnPrefab("npc_fx_pocketwatch_mark")
        -- fx.Transform:SetPosition(pt.x,0,pt.z)
        fx:PushEvent("Set",{pt = pt,scale = Vector3(0.5,0.5,0.5)})
        fx.AnimState:PlayAnimation("idle_pre")
        fx.AnimState:PushAnimation("idle_loop",true)
        fx:DoTaskInTime(1,function()
            fx.AnimState:PlayAnimation("idle_pst")
            fx:ListenForEvent("animover",fx.Remove)
        end)
    end)

    return inst
end

local function wormwood()
    local inst = get_common_inst()

    inst.AnimState:SetBuild("wormwood")
    inst.soundsname = "wormwood"
    inst.prefab_base = "wormwood"

    -- inst.talk_sound = "dontstarve/characters/wormwood/talk_LP"  --- 植物人音效

    inst:Hide()
    if not TheWorld.ismastersim then
        return inst
    end

    inst.customidleanim = function(inst)
        return inst.AnimState:CompareSymbolBuilds("hand", "hand_idle_wormwood") and "idle_wormwood" or nil        
    end


    --------------- 把角色皮肤搞成植物人
    inst:DoTaskInTime(0,function()
        pcall(function()
            local skins = {
                ["feet"] = "",
                ["legs"] = "",
                ["hand"] = "",
                ["base"] = "wormwood_none",
                ["body"] = ""
            }
            local userid = inst:GetPlayer().userid   ----- 如果该ID玩家没购买那个角色，则会出现威尔逊外观替代
            inst.AnimState:AssignItemSkins(userid, skins.base or "", skins.body or "", skins.hand or "", skins.legs or "", skins.feet or "")
            inst.npc_base_lib:___Set_Skin(inst.AnimState,"wormwood","wormwood",skins,nil,"normal_skin","wormwood")
        end)       


        inst.customidleanim = function(inst)
            return inst.AnimState:CompareSymbolBuilds("hand", "hand_idle_wormwood") and "idle_wormwood" or nil        
        end
        inst:Show()
    end)

    ---------------------------------------------------------------------------
    ----- 植物人特效
    inst.plantpool = { 1, 2, 3, 4 }
    for i = #inst.plantpool, 1, -1 do
        --randomize in place
        table.insert(inst.plantpool, table.remove(inst.plantpool, math.random(i)))
    end

    local function PlantTick(inst)
        local pt = inst.npc_base_lib:GetSpawnPoint(inst,math.random(20)/10)
        if pt == nil then
            pt = Vector3(inst.Transform:GetWorldPosition())
        end
        local plant = SpawnPrefab("npc_fx_flowers_of_wormwood")
        plant.Transform:SetPosition(pt.x,0,pt.z)
        local rnd = math.random()
            rnd = table.remove(inst.plantpool, math.clamp(math.ceil(rnd * rnd * #inst.plantpool), 1, #inst.plantpool))
        table.insert(inst.plantpool, rnd)
        plant:SetVariation(rnd)
    end
    inst.planttask = inst:DoPeriodicTask(.25, PlantTick)
    ---------------------------------------------------------------------------
    
    return inst
end

local function wortox()
    local inst = get_common_inst()

    inst.AnimState:SetBuild("wortox")
    inst.soundsname = "wortox"
    inst.prefab_base = "wortox"
    inst.customidleanim = "idle_wortox"  -- 站立休闲动作
    -- inst.talk_sound = "dontstarve/characters/wortox/talk_LP"

    inst:Hide()
    if not TheWorld.ismastersim then
        return inst
    end

    --------------- 把角色皮肤搞成沃拓克斯
    inst:DoTaskInTime(0,function()
        pcall(function()
            local skins = {
                ["feet"] = "",
                ["legs"] = "",
                ["hand"] = "",
                ["base"] = "wortox_none",
                ["body"] = ""
            }
            local userid = inst:GetPlayer().userid   ----- 如果该ID玩家没购买那个角色，则会出现威尔逊外观替代
            inst.AnimState:AssignItemSkins(userid, skins.base or "", skins.body or "", skins.hand or "", skins.legs or "", skins.feet or "")
            inst.npc_base_lib:___Set_Skin(inst.AnimState,"wortox","wortox",skins,nil,"normal_skin","wortox")
        end)
        
        inst.customidleanim = "idle_wortox"  -- 站立休闲动作
        inst:Show()
    end)
    
    return inst
end

local function wurt()
    local inst = get_common_inst()

    inst.AnimState:SetBuild("wurt")
    inst.soundsname = "wurt"
    inst.prefab_base = "wurt"
    inst.customidleanim = "idle_wurt"  -- 站立休闲动作

    -- inst.talk_sound = "dontstarve/characters/wurt/talk_LP"  --- 小鱼人音效
    inst:Hide()
    if not TheWorld.ismastersim then
        return inst
    end

    --------------- 把角色皮肤搞成沃拓克斯
    inst:DoTaskInTime(0,function()
        pcall(function()
            local skins = {
                ["feet"] = "",
                ["legs"] = "",
                ["hand"] = "",
                ["base"] = "wurt_none",
                ["body"] = ""
            }
            local userid = inst:GetPlayer().userid   ----- 如果该ID玩家没购买那个角色，则会出现威尔逊外观替代
            inst.AnimState:AssignItemSkins(userid, skins.base or "", skins.body or "", skins.hand or "", skins.legs or "", skins.feet or "")
            inst.npc_base_lib:___Set_Skin(inst.AnimState,"wurt","wurt",skins,nil,"normal_skin","wurt")
        end)
        

        inst.customidleanim = "idle_wurt"  -- 站立休闲动作
        inst:Show()
    end)
    
    return inst
end

return Prefab("wanda_npc",wanda),
    Prefab("wormwood_npc",wormwood),
    Prefab("wortox_npc",wortox),
    Prefab("wurt_npc",wurt)